package one.stand.controller;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import one.stand.aop.ApiController;
import one.stand.exception.SystemException;
import one.stand.model.ResultModel;
import one.stand.request.*;
import one.stand.request.coupon.GoodsCouponQuery;
import one.stand.response.CompanyCouponResponse;
import one.stand.response.UserCouponResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 用户优惠券查询
 * @author: QIK
 * @CreateDate: 2019/6/24 17:40
 */
@RestController
@RequestMapping("user/coupon")
@Slf4j
public class UserCouponController  extends BaseController {

//    /**
//     * 领取优惠券 -暂存
//     * @param request
//     * @return
//     */
//    @PostMapping("receive")
//    public ResultModel<Boolean> receive(@RequestBody @Valid  CouponRequest request){
//        log.info("receive:{}",request);
//        return userCouponService.receive(request);
//    }

    /**
     * 用户自己的优惠券列表 根据参数区分已经使用或者未使用
     *
     * @param request
     * @return
     */
    @PostMapping("myList")
    public ResultModel myList(@RequestBody @Valid  UserCouponRequest request){
        log.info("myList:{}",request);
        return userCouponService.myList(request);
    }

//    /**
//     * 优惠券领取页面 查询优惠券接口 按倒叙查询所有优惠券 包含已领取和未领取的
//     * @param request
//     * @return
//     */
//    @PostMapping("noReceive")
//    public ResultModel<List<CompanyCouponResponse>> noReceive(@RequestBody @Valid UserCouponRequest request){
//        log.info("noReceive:{}",request);
//        return userCouponService.noReceive(request);
//    }

    /**
     * 用户登录默认发放优惠券
     * @param requestGrant
     */
    @PostMapping("grantCoupon")
    public ResultModel<List<UserCouponResponse>> grantCoupon(@RequestBody @Valid GrantCouponRequest requestGrant){
        log.info("grantCoupon:{}",requestGrant);
        return userCouponService.grantCoupon(requestGrant);
    }


    /**
     * 领取优惠券
     * @param couponRequest
     * @return
     */
    @PostMapping("receiveCoupon")
    public ResultModel<Boolean> receiveCoupon(@RequestBody @Valid CouponRequest couponRequest) throws SystemException {
        log.info("receiveCoupon:{}",couponRequest);
        return userCouponService.receiveCoupon(couponRequest);
    }


    /**
     * 更新优惠券单号
     * @param couponOrderRequest
     * @return
     */
    @PostMapping("updateOrderNum")
    public ResultModel<UserCouponResponse> updateOrderNum(@RequestBody @Valid CouponOrderRequest couponOrderRequest){
        log.info("updateOrderNum:{}",couponOrderRequest);
        return userCouponService.updateOrderNum(couponOrderRequest);
    }


    /**
     * 按商品分类查询我的所有优惠券 和 我的全场通用优惠券
     * @param goodsCouponQuery
     * @return
     */
    @PostMapping("selectUserCouponNotUsed")
    public ResultModel<List<UserCouponResponse>> selectUserCouponNotUsed(@RequestBody @Valid GoodsCouponQuery goodsCouponQuery){
        log.info("updateOrderNum:{}",goodsCouponQuery);
        return userCouponService.selectUserCouponNotUsed(goodsCouponQuery);
    }


}
